package modeler;


import javax.media.opengl.*;

import javax.vecmath.*;

public class TranslateManip extends Manip {

	public TranslateManip(Transformation t) {

	  this.t = t;
  }

	public void dragged(Vector2f mousePosition, Vector2f mouseDelta) {
		
		Vector3f axis = new Vector3f();
		
        if (axisMode == PICK_X) {
                axis.x = 1;
        } else if (axisMode == PICK_Y) {
                axis.y = 1;
        } else if (axisMode == PICK_Z) {
                axis.z = 1;
        }
        
        Vector3f up = new Vector3f(c.getUp());
        Vector3f right = new Vector3f(c.getRight());
        
        up.normalize();
        right.normalize();
        up.scale(mouseDelta.y);
        right.scale(mouseDelta.x);
        up.scale(c.getHeight());
        right.scale(c.getHeight());
        
        Vector3f delta = new Vector3f();
        delta.add(up, right);
        
        float scale = delta.dot(axis);
        
        delta.set(axis);
        delta.scale(scale);
        t.T.add(delta);
	}
  ////////////////////////////////////////////////////////////////////////////////////////////////////
  // Render the manipulator
  ////////////////////////////////////////////////////////////////////////////////////////////////////
  
  Vector3f skewX = new Vector3f();
  Vector3f skewY = new Vector3f();
  Vector3f skewZ = new Vector3f();
  public void glRender(GLAutoDrawable d, double scale) {

    GL gl = d.getGL();
    gl.glPushAttrib(GL.GL_COLOR);

    gl.glPushAttrib(GL.GL_LIGHTING);
    gl.glDisable(GL.GL_LIGHTING);

    gl.glPushAttrib(GL.GL_DEPTH_TEST);
    gl.glDisable(GL.GL_DEPTH_TEST);
    
    gl.glPushMatrix();
    glDoLocation(gl, t);

    gl.glScaled(scale, scale, scale);

    normalizedTransformedAxes(skewX, skewY, skewZ);
    
    gl.glPushMatrix();
	glRotateTo(gl,skewX);
    gl.glColor4d(0.8, 0, 0, 1);
    gl.glLoadName(PICK_X);
    glRenderArrow(gl);
    gl.glPopMatrix();
    
    gl.glPushMatrix();
    glRotateTo(gl,skewY);
    gl.glColor4d(0, 0.8, 0, 1);
    gl.glLoadName(PICK_Y);
    glRenderArrow(gl);
    gl.glPopMatrix();
    
    gl.glPushMatrix();
    glRotateTo(gl,skewZ);
    gl.glColor4d(0, 0, 0.8, 1);
    gl.glLoadName(PICK_Z);
    glRenderArrow(gl);
    gl.glPopMatrix();    

    gl.glLoadName(PICK_OTHER);
    gl.glColor4d(0.8, 0.8, 0, 1);
    glRenderBox(gl);

    gl.glPopMatrix();

    gl.glPopAttrib();
    gl.glPopAttrib();
    gl.glPopAttrib();
  }

}

	